package com.eastfair.home.controller;

/**
 * @Author suolong
 * @Date 2022/8/8 20:58
 */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeServiceInventoryCheckService;
import com.eastfair.venueservice.dto.ServiceInventoryCheckDTO;
import com.eastfair.venueservice.dto.ServiceInventoryCheckQuery;
import com.eastfair.venueservice.vo.ServiceInventoryCheckVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * 库存盘点
 * </p>
 *
 * @author lyw
 * @date 2022-08-08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/homeServiceInventoryCheck")
@Api(value = "homeServiceInventoryCheck", tags = "库存盘点")
public class HomeServiceInventoryCheckController {

    @Resource
    private HomeServiceInventoryCheckService homeServiceInventoryCheckService;

    /**
     * 新增盘点记录
     * @param serviceInventoryCheckDTO
     * @return
     */
    @ApiOperation(value = "新增盘点记录")
    @SysLog("添加盘点记录")
    @PostMapping(value = "/saveInventoryCheck")
    public R<Boolean> saveInventoryCheck(@RequestBody ServiceInventoryCheckDTO serviceInventoryCheckDTO){
        try {
            return R.success(homeServiceInventoryCheckService.saveInventoryCheck(serviceInventoryCheckDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 修改盘点记录
     * @param serviceInventoryCheckDTO
     * @return
     */
    @ApiOperation(value = "修改盘点记录")
    @SysLog("修改盘点记录")
    @PostMapping(value = "/updateInventoryCheck")
    public R<Boolean> updateInventoryCheck(@RequestBody ServiceInventoryCheckDTO serviceInventoryCheckDTO){
        try {
            return R.success(homeServiceInventoryCheckService.updateInventoryCheck(serviceInventoryCheckDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 删除盘点记录
     * @param serviceInventoryCheckDTO
     * @return
     */
    @ApiOperation(value = "删除盘点记录")
    @SysLog("删除盘点记录")
    @PostMapping(value = "/delInventoryCheck")
    public R<Boolean> delInventoryCheck(@RequestBody ServiceInventoryCheckDTO serviceInventoryCheckDTO){
        try {
            return R.success(homeServiceInventoryCheckService.delInventoryCheck(serviceInventoryCheckDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 查询盘点记录
     * @param serviceInventoryCheckQuery
     * @return
     */
    @ApiOperation(value = "查询盘点记录")
    @PostMapping(value = "/queryCheckList")
    public R<Page<ServiceInventoryCheckVO>> queryCheckList(@RequestBody PageParams<ServiceInventoryCheckQuery> serviceInventoryCheckQuery){
        log.info("queryCheckList - 查询盘点记录, serviceInventoryCheckQuery={}", serviceInventoryCheckQuery);
        try {
            return R.success(homeServiceInventoryCheckService.queryCheckList(serviceInventoryCheckQuery));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 查询盘点记录明细
     * @param serviceInventoryCheckQuery
     * @return
     */
    @ApiOperation(value = "查询盘点记录明细")
    @PostMapping(value = "/queryCheckDetailList")
    public R<ServiceInventoryCheckVO> queryCheckDetailList(@RequestBody ServiceInventoryCheckQuery serviceInventoryCheckQuery){
        log.info("queryCheckDetailList - 查询盘点记录明细, serviceInventoryCheckQuery={}", serviceInventoryCheckQuery);
        try {
            return R.success(homeServiceInventoryCheckService.queryCheckDetailList(serviceInventoryCheckQuery));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 查询新的盘点单号
     * @return
     */
    @ApiOperation(value = "查询新的盘点单号")
    @GetMapping(value = "/queryNewCheckNo")
    public R<String> queryNewCheckNo(){
        log.info("queryNewCheckNo - 查询新的盘点单号");
        try {
            return R.success(homeServiceInventoryCheckService.queryNewCheckNo());
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }
}
